package com.yuandian.management.service.impl;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.exception.NacosException;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.service.ConfProbeConfigService;
import com.yuandian.management.vo.ProbeConfigVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 迁移至 BPM3.0
 * agentip管理表-Service实现
 * @author zfsn
 * @date 2023-4-14
 */
@Service
@RequiredArgsConstructor
public class ConfProbeConfigServiceImpl implements ConfProbeConfigService {

	private final NacosConfigManager nacosConfigManager;

	private static Map<String,String> codeAndRemarksMap = new HashMap<>();
	static {
		codeAndRemarksMap.put("open_http_decoder", "http 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_spark_decoder", "spark 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_tns_decoder", "tns 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_giop_decoder", "giop 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_tuxedo_decoder", "tuxedo 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_mq_decoder", "mq 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_db2_decoder", "db2 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_mysql_decode", "mysql 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_tds_decoder", "tds 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_cics_decoder", "cics 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_ajp_decoder", "ajp 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_remote_decoder", "remote 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_socket_decoder", "银行 socket 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_t3_decoder", "t3 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_redis_decoder", "redis 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_mqtt_decoder", "mqtt 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_ssl_decoder", "ssl 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_other_decoder", "other 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_openwire_decoder", "openwire 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_amqp_decoder", "amqp 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_dubbo_decoder", "dubbo 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_signature_decoder", "signature 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_psocket_decoder", "pass 平台 socket 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_rtsp_decoder", "rtsp 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_rtmp_decoder", "rtmp 协议解码器开关[0,1]");
		codeAndRemarksMap.put("open_sip_decoder", "sip 协议解码器开关[0,1]");
		codeAndRemarksMap.put("WebFlow", "60011-22 web数据流开关 switch[0,1]");
		codeAndRemarksMap.put("MiddFlow", "60011-23 Midd数据流开关[0,1]");
		codeAndRemarksMap.put("DBFlow", "60011-24 DB数据流开关[0,1]");
		codeAndRemarksMap.put("VideoFlow", "60011-31 video数据流开关[0,1]");
		codeAndRemarksMap.put("BaseDataFlow", "60014-28 apm 网络基础数据流开关[0,1]");
		codeAndRemarksMap.put("UnrecognizedBaseDataFlow", "60014-28 apm 网络基础未识别数据流开关[0,1]");
		codeAndRemarksMap.put("web_batch_num_messages", "web流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("midd_batch_num_messages", "midd流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("db_batch_num_messages", "DB流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("video_batch_num_messages", "video流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("base_batch_num_messages", "apm网络基础流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("AppFlow", "60001-17 数据流开关[0,1]");
		codeAndRemarksMap.put("QoeFlow", "60001-18 数据流开关[0,1]");
		codeAndRemarksMap.put("UsrFlow", "60001-19 数据流开关[0,1]");
		codeAndRemarksMap.put("DataStreamCollect", "发送60010-20 数据流开关[0,1]");
		codeAndRemarksMap.put("app_batch_num_messages", "app流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("qoe_batch_num_messages", "qoe流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("usr_batch_num_messages", "usr流批量发送数据条数[0,1000000]");
		codeAndRemarksMap.put("net_hall_session_key", "提取sessionid的关键字，支持正则表达式[0,300]");
		codeAndRemarksMap.put("isSendVarFlowData", "是否发送body数据的开关");
		codeAndRemarksMap.put("SendSocketDataTimer", "数据输出的聚合数据的超时时间[0,1000000]");
		codeAndRemarksMap.put("saveOriNums", "专属指标数据样本数量[10,1000000]");
		codeAndRemarksMap.put("version_server", "配置发送探针历史版本和当前版本信息的url地址[0,300]");
		codeAndRemarksMap.put("ag_state_server", "agent 状态数据服务器URL[0,300][0,300]");
		codeAndRemarksMap.put("del_seg", "配置http资源需要去除的加密参数的参数名字符串[0,300]");
		codeAndRemarksMap.put("extractSegment", "配置提取http协议解码器url中的字段[0,300][0,300]");
		codeAndRemarksMap.put("recoHttpBusOpt", "开启加速业务匹配性能的开关[0, 1]");
		codeAndRemarksMap.put("HttpUrlHeadMatch", "开启http的url头部优先匹配的开关[0, 1]");
		codeAndRemarksMap.put("tns", "配置tns协议的识别端口，支持配置多个[0,65535]");
		codeAndRemarksMap.put("mysql", "配置mysql协议的识别端口[0,65535]");
		codeAndRemarksMap.put("ajp", "配置ajp协议的识别端口[0,65535]");
		codeAndRemarksMap.put("remote", "配置remote协议的识别端口[0,65535]");
		codeAndRemarksMap.put("socket", "配置socket协议的识别端口[0,65535]");
		codeAndRemarksMap.put("cics", "配置cics协议的识别端口[0,65535]");
		codeAndRemarksMap.put("redis", "配置redis协议的识别端口[0,65535]");
		codeAndRemarksMap.put("t3", "配置t3协议的识别端口[0,65535]");
		codeAndRemarksMap.put("mqtt", "配置mqtt协议的识别端口[0,65535]");
		codeAndRemarksMap.put("ssl", "配置ssl协议的识别端口[0,65535]");
		codeAndRemarksMap.put("openwire", "配置openwire协议的识别端口[0,65535]");
		codeAndRemarksMap.put("amqp", "配置amqp协议的识别端口[0,65535]");
		codeAndRemarksMap.put("signature", "配置签名协义的识别端口[0,65535]");
		codeAndRemarksMap.put("tds", "配置tds协议的识别端口[0,65535]");
		codeAndRemarksMap.put("psocket", "配置psocket协议的识别端口[0,65535]");
		codeAndRemarksMap.put("rtsp", "配置rtsp协议的识别端口[0,65535]");
		codeAndRemarksMap.put("rtmp", "配置rtmp协议的识别端口[0,65535]");
		codeAndRemarksMap.put("sip", "配置sip协议的识别端口[0,65535]");

	}

	/**
	 * 去nacos 拉取数据
	 * 通过ip 获取ip 配置详情
	 * @param ip
	 * @return
	 */
	@Override
	public R getConfigDetailByIp(String ip) {
		List<Map<String, Object>> list = new ArrayList<>();
		try {
			String configProperty = nacosConfigManager.getConfigService().getConfig(ip + "_kafkasync.json", "UDPROBE_CONF", 5000);
			JSONObject jsonObject = JSONUtil.parseObj(configProperty);
			int num = 1;
			for (Map.Entry<String, Object> stringObjectEntry : jsonObject) {
				JSONObject jsons = (JSONObject)stringObjectEntry.getValue();
				for (Map.Entry<String, Object> objectEntry : jsons) {
					Map<String, Object> map = new HashMap<>();
					map.put("configName", objectEntry.getKey());
					Object value = null;
					if (objectEntry.getValue() instanceof Boolean){
						value = (Boolean)objectEntry.getValue() ? 1 : 0;
						map.put("valueType", "boolean");
					}else if(objectEntry.getValue() instanceof JSONArray){
						value = objectEntry.getValue().toString();
					}else {
						value = objectEntry.getValue();
					}
					map.put("configDetails", value);
					map.put("id", num++);
					map.put("remark", codeAndRemarksMap.get(objectEntry.getKey()));
					list.add(map);
				}
			}
		} catch (NacosException e) {
			e.printStackTrace();
		}
		return R.ok(list);
	}

	/**
	 * 更新探针 配置信息
	 *
	 * @param configContext @return
	 */
	@Override
	public R updateProbeConfigDetails(ProbeConfigVo configContext) {
		String dataList = "{\"dataList\": " + configContext.getConfigContext() + "}";
		try {
			JSONObject jsonObject = JSONUtil.parseObj(dataList);
			JSONArray jsonArray = (JSONArray)jsonObject.get("dataList");
			Map<String, String> map = new HashMap<>();
			map.put("open_http_decoder", "decoderswitch");
			map.put("open_http_decoder", "decoderswitch");
			map.put("open_spark_decoder", "decoderswitch");
			map.put("open_tns_decoder", "decoderswitch");
			map.put("open_giop_decoder", "decoderswitch");
			map.put("open_tuxedo_decoder", "decoderswitch");
			map.put("open_mq_decoder", "decoderswitch");
			map.put("open_db2_decoder", "decoderswitch");
			map.put("open_mysql_decode", "decoderswitch");
			map.put("open_tds_decoder", "decoderswitch");
			map.put("open_cics_decoder", "decoderswitch");
			map.put("open_ajp_decoder", "decoderswitch");
			map.put("open_remote_decoder", "decoderswitch");
			map.put("open_socket_decoder", "decoderswitch");
			map.put("open_t3_decoder", "decoderswitch");
			map.put("open_redis_decoder", "decoderswitch");
			map.put("open_mqtt_decoder", "decoderswitch");
			map.put("open_ssl_decoder", "decoderswitch");
			map.put("open_other_decoder", "decoderswitch");
			map.put("open_openwire_decoder", "decoderswitch");
			map.put("open_amqp_decoder", "decoderswitch");
			map.put("open_dubbo_decoder", "decoderswitch");
			map.put("open_signature_decoder", "decoderswitch");
			map.put("open_psocket_decoder", "decoderswitch");
			map.put("open_rtsp_decoder", "decoderswitch");
			map.put("open_rtmp_decoder", "decoderswitch");
			map.put("open_sip_decoder", "decoderswitch");
			map.put("WebFlow", "bpm_flow_switch");
			map.put("MiddFlow", "bpm_flow_switch");
			map.put("DBFlow", "bpm_flow_switch");
			map.put("BaseDataFlow", "bpm_flow_switch");
			map.put("UnrecognizedBaseDataFlow", "bpm_flow_switch");
			map.put("web_batch_num_messages", "bpm_flow_send_nums");
			map.put("midd_batch_num_messages", "bpm_flow_send_nums");
			map.put("db_batch_num_messages", "bpm_flow_send_nums");
			map.put("video_batch_num_messages", "bpm_flow_send_nums");
			map.put("base_batch_num_messages", "bpm_flow_send_nums");
			map.put("AppFlow", "apm_flow_switch");
			map.put("QoeFlow", "apm_flow_switch");
			map.put("UsrFlow", "apm_flow_switch");
			map.put("DataStreamCollect", "apm_flow_switch");
			map.put("app_batch_num_messages", "apm_flow_send_nums");
			map.put("qoe_batch_num_messages", "apm_flow_send_nums");
			map.put("usr_batch_num_messages", "apm_flow_send_nums");
			map.put("net_hall_session_key", "others");
			map.put("isSendVarFlowData", "others");
			map.put("SendSocketDataTimer", "others");
			map.put("saveOriNums", "others");
			map.put("version_server", "others");
			map.put("ag_state_server", "others");
			map.put("del_seg", "others");
			map.put("extractSegment", "others");
			map.put("host_ip_verify", "others");
			map.put("recoHttpBusOpt", "others");
			map.put("HttpUrlHeadMatch", "others");
			map.put("tns", "protocol");
			map.put("mysql", "protocol");
			map.put("ajp", "protocol");
			map.put("remote", "protocol");
			map.put("socket", "protocol");
			map.put("cics", "protocol");
			map.put("redis", "protocol");
			map.put("t3", "protocol");
			map.put("mqtt", "protocol");
			map.put("ssl", "protocol");
			map.put("openwire", "protocol");
			map.put("amqp", "protocol");
			map.put("signature", "protocol");
			map.put("tds", "protocol");
			map.put("psocket", "protocol");
			map.put("rtsp", "protocol");
			map.put("rtmp", "protocol");
			map.put("sip", "protocol");
			map.put("D2DStudy", "d2d_study");
			map.put("D2DStudyCount", "d2d_study");
			map.put("D2DStudyTimes", "d2d_study");
			map.put("D2DStudyInterval", "d2d_study");
			map.put("publicFilter", "D2DStudyFilter");
			map.put("httpFilter", "D2DStudyFilter");
			map.put("sparkFilter", "D2DStudyFilter");

			JSONObject entries = new JSONObject();
			for (Object data : jsonArray) {
				if (data instanceof JSONObject){
					JSONObject jsonMap = (JSONObject) data;
					Map<String, Object> configList = (Map<String, Object>)entries.computeIfAbsent(map.get(jsonMap.get("configName")), k -> new HashMap<>());
					Object value = null;
					if(Objects.equals(jsonMap.get("valueType"), "boolean")){
						value = Objects.equals(jsonMap.get("configDetails"), 1);
					}else {
						value = jsonMap.get("configDetails");
					}
					configList.put(String.valueOf(jsonMap.get("configName")), value);
				}
			}

			boolean updateFlag = nacosConfigManager.getConfigService().publishConfig(configContext.getIp() + "_probeConfigDetail.json", "UDAGENT_CONF", entries.toString());
			if (!updateFlag){
				return R.failed();
			}
		} catch (NacosException e) {
			e.printStackTrace();
		}
		return R.ok();
	}

	public static void main(String[] args) {
		String json = "{\"dataList\":[\n" +
				"    {\n" +
				"      \"configName\": \"open_http_decoder\",\n" +
				"      \"configDetails\": 1,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"http 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_spark_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"spark 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_tns_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"tns 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_giop_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"giop 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_tuxedo_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"tuxedo 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_mq_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"mq 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_db2_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"db2 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_mysql_decode\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"mysql 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_tds_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"tds 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_cics_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"cics 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_ajp_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"ajp 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_remote_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"remote 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_socket_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"银行 socket 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_t3_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"t3 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_redis_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"redis 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_mqtt_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"mqtt 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_ssl_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"ssl 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_other_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"other 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_openwire_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"openwire 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_amqp_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"amqp 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_dubbo_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"dubbo 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_signature_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"signature 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"open_psocket_decoder\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"pass 平台 socket 协议解码器开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"WebFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60011-22 web数据流开关 switch[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"MiddFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60011-23 Midd数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"DBFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60011-24 DB数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"BaseDataFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60014-28 apm 网络基础数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"UnrecognizedBaseDataFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60014-28 apm 网络基础未识别数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"web_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"web流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"midd_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"midd流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"db_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"DB流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"base_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"apm网络基础流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"AppFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60001-17 数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"QoeFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60001-18 数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"UsrFlow\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"60001-19 数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"DataStreamCollect\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"发送60010-20 数据流开关[0,1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"app_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"app流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"qoe_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"qoe流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"usr_batch_num_messages\",\n" +
				"      \"configDetails\": 10000,\n" +
				"      \"remark\": \"usr流批量发送数据条数[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"D2DStudy\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"D2DStudyCount\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"D2DStudyTimes\",\n" +
				"      \"configDetails\": 300,\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"D2DStudyInterval\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"net_hall_session_key\",\n" +
				"      \"configDetails\": \"sessionid\",\n" +
				"      \"remark\": \"提取sessionid的关键字，支持正则表达式[0,300]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"isSendVarFlowData\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"是否发送body数据的开关\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"SendSocketDataTimer\",\n" +
				"      \"configDetails\": 15,\n" +
				"      \"remark\": \"数据输出的聚合数据的超时时间[0,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"saveOriNums\",\n" +
				"      \"configDetails\": 10,\n" +
				"      \"remark\": \"专属指标数据样本数量[10,1000000]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"version_server\",\n" +
				"      \"configDetails\": \"10.1.2.14:8081/yd-system-config-web/version/addversion\",\n" +
				"      \"remark\": \"配置发送探针历史版本和当前版本信息的url地址[0,300]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"del_seg\",\n" +
				"      \"configDetails\": \"\",\n" +
				"      \"remark\": \"配置http资源需要去除的加密参数的参数名字符串[0,300]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"extractSegment\",\n" +
				"      \"configDetails\": \"\",\n" +
				"      \"remark\": \"配置提取http协议解码器url中的字段[0,300][0,300]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"ag_state_server\",\n" +
				"      \"configDetails\": \"10.1.2.37:8080/yd-system-config-web/modules/probe/agent/save.action\",\n" +
				"      \"remark\": \"agent 状态数据服务器URL[0,300][0,300]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"host_ip_verify\",\n" +
				"      \"configDetails\": \"10.1.1.117\",\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"recoHttpBusOpt\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"remark\": \"开启加速业务匹配性能的开关[0, 1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"HttpUrlHeadMatch\",\n" +
				"      \"configDetails\": 0,\n" +
				"      \"valueType\": \"boolean\",\n" +
				"      \"remark\": \"开启http的url头部优先匹配的开关[0, 1]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"tns\",\n" +
				"      \"configDetails\": \"[1536,1521]\",\n" +
				"      \"remark\": \"配置tns协议的识别端口，支持配置多个[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"mysql\",\n" +
				"      \"configDetails\": \"[3306]\",\n" +
				"      \"remark\": \"配置mysql协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"ajp\",\n" +
				"      \"configDetails\": \"[8009]\",\n" +
				"      \"remark\": \"配置ajp协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"remote\",\n" +
				"      \"configDetails\": \"[18951,18903,18901]\",\n" +
				"      \"remark\": \"配置remote协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"socket\",\n" +
				"      \"configDetails\": \"[19005]\",\n" +
				"      \"remark\": \"配置socket协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"cics\",\n" +
				"      \"configDetails\": \"[50755,40755,10999,30755,20755,10755]\",\n" +
				"      \"remark\": \"配置cics协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"redis\",\n" +
				"      \"configDetails\": \"[6379]\",\n" +
				"      \"remark\": \"配置redis协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"t3\",\n" +
				"      \"configDetails\": \"[8003,8002,8001]\",\n" +
				"      \"remark\": \"配置t3协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"mqtt\",\n" +
				"      \"configDetails\": \"[1883]\",\n" +
				"      \"remark\": \"配置mqtt协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"ssl\",\n" +
				"      \"configDetails\": \"[443]\",\n" +
				"      \"remark\": \"配置ssl协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"openwire\",\n" +
				"      \"configDetails\": \"[61616]\",\n" +
				"      \"remark\": \"配置openwire协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"amqp\",\n" +
				"      \"configDetails\": \"[5672,5671]\",\n" +
				"      \"remark\": \"配置amqp协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"signature\",\n" +
				"      \"configDetails\": \"[50010]\",\n" +
				"      \"remark\": \"配置签名协义的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"tds\",\n" +
				"      \"configDetails\": \"[1433]\",\n" +
				"      \"remark\": \"配置tds协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"psocket\",\n" +
				"      \"configDetails\": \"[11102]\",\n" +
				"      \"remark\": \"配置psocket协议的识别端口[0,65535]\"\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"publicFilter\",\n" +
				"      \"configDetails\": \"[]\",\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"httpFilter\",\n" +
				"      \"configDetails\": \"[\\\"Content-Type\\\",\\\"Content-Length\\\",\\\"Accept\\\",\\\"Accept-Language\\\",\\\"Accept-Encoding\\\",\\\"User-Agent\\\",\\\"Connection\\\",\\\"Cache-Control\\\"]\",\n" +
				"      \"remark\": null\n" +
				"    },\n" +
				"    {\n" +
				"      \"configName\": \"sparkFilter\",\n" +
				"      \"configDetails\": \"[]\",\n" +
				"      \"remark\": null\n" +
				"    }\n" +
				"  ]}";

		JSONObject jsonObject = JSONUtil.parseObj(json);
		JSONArray dataList = (JSONArray)jsonObject.get("dataList");
		Map<String, String> map = new HashMap<>();
		map.put("open_http_decoder", "decoderswitch");
		map.put("open_http_decoder", "decoderswitch");
		map.put("open_spark_decoder", "decoderswitch");
		map.put("open_tns_decoder", "decoderswitch");
		map.put("open_giop_decoder", "decoderswitch");
		map.put("open_tuxedo_decoder", "decoderswitch");
		map.put("open_mq_decoder", "decoderswitch");
		map.put("open_db2_decoder", "decoderswitch");
		map.put("open_mysql_decode", "decoderswitch");
		map.put("open_tds_decoder", "decoderswitch");
		map.put("open_cics_decoder", "decoderswitch");
		map.put("open_ajp_decoder", "decoderswitch");
		map.put("open_remote_decoder", "decoderswitch");
		map.put("open_socket_decoder", "decoderswitch");
		map.put("open_t3_decoder", "decoderswitch");
		map.put("open_redis_decoder", "decoderswitch");
		map.put("open_mqtt_decoder", "decoderswitch");
		map.put("open_ssl_decoder", "decoderswitch");
		map.put("open_other_decoder", "decoderswitch");
		map.put("open_openwire_decoder", "decoderswitch");
		map.put("open_amqp_decoder", "decoderswitch");
		map.put("open_dubbo_decoder", "decoderswitch");
		map.put("open_signature_decoder", "decoderswitch");
		map.put("open_psocket_decoder", "decoderswitch");
		map.put("open_rtsp_decoder", "decoderswitch");
		map.put("open_rtmp_decoder", "decoderswitch");
		map.put("open_sip_decoder", "decoderswitch");
		map.put("WebFlow", "bpm_flow_switch");
		map.put("MiddFlow", "bpm_flow_switch");
		map.put("DBFlow", "bpm_flow_switch");
		map.put("BaseDataFlow", "bpm_flow_switch");
		map.put("UnrecognizedBaseDataFlow", "bpm_flow_switch");
		map.put("web_batch_num_messages", "bpm_flow_send_nums");
		map.put("midd_batch_num_messages", "bpm_flow_send_nums");
		map.put("db_batch_num_messages", "bpm_flow_send_nums");
		map.put("video_batch_num_messages", "bpm_flow_send_nums");
		map.put("base_batch_num_messages", "bpm_flow_send_nums");
		map.put("AppFlow", "apm_flow_switch");
		map.put("QoeFlow", "apm_flow_switch");
		map.put("UsrFlow", "apm_flow_switch");
		map.put("DataStreamCollect", "apm_flow_switch");
		map.put("app_batch_num_messages", "apm_flow_send_nums");
		map.put("qoe_batch_num_messages", "apm_flow_send_nums");
		map.put("usr_batch_num_messages", "apm_flow_send_nums");
		map.put("net_hall_session_key", "others");
		map.put("isSendVarFlowData", "others");
		map.put("SendSocketDataTimer", "others");
		map.put("saveOriNums", "others");
		map.put("version_server", "others");
		map.put("ag_state_server", "others");
		map.put("del_seg", "others");
		map.put("extractSegment", "others");
		map.put("host_ip_verify", "others");
		map.put("recoHttpBusOpt", "others");
		map.put("HttpUrlHeadMatch", "others");
		map.put("tns", "protocol");
		map.put("mysql", "protocol");
		map.put("ajp", "protocol");
		map.put("remote", "protocol");
		map.put("socket", "protocol");
		map.put("cics", "protocol");
		map.put("redis", "protocol");
		map.put("t3", "protocol");
		map.put("mqtt", "protocol");
		map.put("ssl", "protocol");
		map.put("openwire", "protocol");
		map.put("amqp", "protocol");
		map.put("signature", "protocol");
		map.put("tds", "protocol");
		map.put("psocket", "protocol");
		map.put("rtsp", "protocol");
		map.put("rtmp", "protocol");
		map.put("sip", "protocol");
		map.put("D2DStudy", "d2d_study");
		map.put("D2DStudyCount", "d2d_study");
		map.put("D2DStudyTimes", "d2d_study");
		map.put("D2DStudyInterval", "d2d_study");
		map.put("publicFilter", "D2DStudyFilter");
		map.put("httpFilter", "D2DStudyFilter");
		map.put("sparkFilter", "D2DStudyFilter");

		JSONObject entries = new JSONObject();
		for (Object data : dataList) {
			if (data instanceof JSONObject){
				JSONObject jsonMap = (JSONObject) data;
				Map<String, Object> configList = (Map<String, Object>)entries.computeIfAbsent(map.get(jsonMap.get("configName")), k -> new HashMap<>());
				Object value = null;
				if(Objects.equals(jsonMap.get("valueType"), "boolean")){
					value = Objects.equals(jsonMap.get("configDetails"), 1);
				}else {
					value = jsonMap.get("configDetails");
				}
				configList.put(String.valueOf(jsonMap.get("configName")), value);
			}
		}

		System.out.println(entries.toString());
	}
}
